let id = new URLSearchParams(location.search).get('id')
let BookNameinput = document.querySelector('[name=Bookname]')
let authorinput = document.querySelector('[name=author]')
console.log(BookNameinput,authorinput);
if(id){
  axios({
    method: 'get',
    url: `http://localhost:3000/bookList/${id}`,
   
  }).then(res => {
    // console.log(res);
    BookNameinput.value=res.data.BookName
    authorinput.value=res.data.author
  })
}
// if (id) {
//   // 修改
//   console.log(BookNameinput.value,authorinput.value);
//   axios({
//     method: 'put',
//     url: `http://localhost:3000/bookList/${id}`,
//     data: {
//       BookName: BookNameinput.value,
//       author: authorinput.value
//     }
//   }).then(res => {
//     location.href = './index.html'
//   })
// } else {
//   axios(
//     {
//       method: 'post',
//       url: `http://localhost:3000/bookList`,
//       data: {
//         BookName: BookNameinput.value,
//         author: authorinput.value
//       }
//     }

//   ).then(res => {
//     location.href = './index.html'
//   })
// }
function yes() {

  if (id) {
  // 修改
  console.log(BookNameinput.value,authorinput.value);
  axios({
    method: 'put',
    url: `http://localhost:3000/bookList/${id}`,
    data: {
      BookName: BookNameinput.value,
      author: authorinput.value
    }
  }).then(res => {
    location.href = './index.html'
  })
} else {
  axios(
    {
      method: 'post',
      url: `http://localhost:3000/bookList`,
      data: {
        BookName: BookNameinput.value,
        author: authorinput.value
      }
    }

  ).then(res => {
    location.href = './index.html'
  })
}
}
function no() {
  location.href='./index.html'
  
}